Table of Contents
Using PdfImageContent

Follow these steps to use a PdfImageContent object:

  1. Load the image into a System.Drawing.Image object. For example:

    //Load the image
    System.Drawing.Image image = 
        System.Drawing.Image.FromFile("c:\\hello.gif");
  2. Create a PdfImage object using the System.Drawing.Image object:

    //Create a new PdfImage object
    EO.Pdf.Drawing.PdfImage pdfImage = new EO.Pdf.Drawing.PdfImage(image);
  3. Create a PdfImageContent object using the PdfImage object:

    //Create a new PdfImageContent object
    EO.Pdf.Contents.PdfImageContent content = new EO.Pdf.Contents.PdfImageContent(pdfImage);
  4. Adjust the PdfImageContent's GfxMatrix to move the image to the desired location:

    //Move the image
    content.GfxMatrix.Translate(100, 100);
  5. Call the PdfImageContent's AutoScale to scale the image to its original size:

    //Scale the image
    content.AutoScale();

    Without scaling, PDF always renders an image inside a 1 by 1 (1/72 inch by 1/72 inch) block in the user space. AutoScale automatically scales the image to its original size based on the image's pixel width/height and horizontal/vertical DPI value.

    Optionally, you can call Scale method on the PdfMatrix class to scale the image directly.

  6. Add the PdfImageContent into the page's Contents collection:

    //Place the image on the page
    page.Contents.Add(content);

Below is the full code:

//Create a new PDF document
PdfDocument doc = new PdfDocument();

//Create a new page
PdfPage page = doc.Pages.Add();

//Load the image
System.Drawing.Image image = 
    System.Drawing.Image.FromFile("c:\\hello.gif");

//Create a new PdfImage object
EO.Pdf.Drawing.PdfImage pdfImage = new EO.Pdf.Drawing.PdfImage(image);

//Create a new PdfImageContent object
EO.Pdf.Contents.PdfImageContent content = new EO.Pdf.Contents.PdfImageContent(pdfImage);

//Move the image
content.GfxMatrix.Translate(100, 100);

//Scale the image
content.AutoScale();

//Place the image on the page
page.Contents.Add(content);